// import {
// 	userInfos
// } from '@/api/login.js'
// import uView from '@/uni_modules/uview-ui'
export const state = {
	appConfig: {},
	userInfo: {}, //用户数据
	carInfo: {}, //车辆信息
};
export const mutations = {
	//储存用户信息
	setUserInfo(state, data) {
		if (data) {
			state.userInfo = Object.assign({}, state.userInfo, data);
			uni.setStorageSync('userInfo', state.userInfo);
		}
	},
	setAppConfig(state, data) {
		if (data) {
			state.appConfig = data;
		}
	},
	// 退出APP
	loginOut(state) {
		state.userInfo = {};
		uni.clearStorage();
	},
	setCarInfo(state, data) {
		state.carInfo = data;
		uni.setStorageSync('carInfo', state.carInfo);
	}

};
export const getters = {
	getCouponNum: (state) => {
		if (uni.getStorageSync('couponNum')) {
			return uni.getStorageSync('couponNum')
		} else {
			var number = state.couponNum ? state.couponNum : 0
			return number
		}
	}
}
export const actions = {
	// 登录
	Login({
		commit,
		state
	}, params) {
		return new Promise((resolve, reject) => {
			login(params).then(re => {
				uni.setStorageSync('token', re.data.token)
				commit('setUserInfo', re.data)
				resolve()
			}).catch(error => {
				reject(error)
			})
		})
	},
	UserInfo({
		commit
	}) {
		return new Promise((resolve, reject) => {
			userInfos({}).then(res => {
				commit('setUserInfo', res.data.info ? res.data.info : res.data);
				resolve()
			}).catch(error => {
				reject(error)
			})
		})
	},
};